package com.atguigu.srb.core.controller.admin;


import com.atguigu.common.results.R;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.vo.BorrowerApprovalVO;
import com.atguigu.srb.core.pojo.vo.BorrowerDetailVO;
import com.atguigu.srb.core.service.BorrowerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2022-10-24
 */
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {
    @Resource  //java自带的注解
    BorrowerService borrowerService;
    @ApiOperation("更新借款人的认证状态+积分")
    @PutMapping("approval")
    public R approval(@RequestBody BorrowerApprovalVO approvalVO){
        borrowerService.approval(approvalVO);
        return R.success().message("审核成功");
    }
    @ApiOperation("根据借款人id查询借款人详情")
    @GetMapping("borrowerDetail/{id}")
    public R borrowerDetail(@PathVariable("id")String id){
        BorrowerDetailVO borrowerDetailVO =
                borrowerService.selectBorrowerDetail(id);
        return R.success().data("item",borrowerDetailVO);
    }


    @ApiOperation("带条件查询借款人审核信息分页数据")
    @GetMapping("list/{pageNum}/{pageSize}")
    public R listBorrowers(@PathVariable("pageNum") Integer pageNum,
                           @PathVariable("pageSize") Integer pageSize,
                           @ApiParam("查询条件")
                           @RequestParam("key")String key){
        //是否要定义vo类就看 接收的参数或者响应的数据 已存在的类是否能够完全封装
        Page<Borrower> page = new Page<>(pageNum, pageSize);
        borrowerService.listBorrowers(page , key);
        return  R.success().data("page",page);
    }

}

